package com.bana.fvs.app.util;

import android.text.TextUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Author : yanftch
 * Date : 2018/3/11
 * Time : 21:47
 * Desc :
 */

public class TimeUtils {

    public static String getCurrentTime() {
        return getCurrentTime("yyyy-MM-dd HH:mm");
    }

    public static String getCurrentTime(String str){
        SimpleDateFormat format = new SimpleDateFormat(str);
        String format1 = format.format(new Date());
        return format1;
    }

    public static long timeToMills(String time) {
        if(TextUtils.isEmpty(time)){
            return 0;
        }
       String t= getCurrentTime("yyyy-MM-dd")+" "+time;

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        long l = 0;
        try {
            Date parse = format.parse(t);

            l = (System.currentTimeMillis() - parse.getTime())/1000;
        } catch (ParseException e) {
            return l;
        }
        return l;
    }


    public static String secondToMin(int second){
        if(second>=0) {
            int min = second / 60;
            int s = second % 60;

            String min1=min>=10?min+"":"0"+min;
            String s1=s>=10?s+"":"0"+s;
            return min1+":"+s1;
        }
        return "";
    }


}
